#Ricana-IP6-2020 Data Analysis
#Revised 2020.06.13

#Set working directory & load libraries
setwd("set working directory")
library(ggplot2)
library(dplyr)
library(ggpubr)
library(scales)


#Figure 2: HIV IP6 quantification of HEK293FT, IPPK-KO, IPMK-KO cells with 33% PAGE

#Fig 2B: IP6
#Export .eps at 325 width, 225 height
ip6KOpage = read.csv(file="fig2bData-IP6page.csv",header=T)
ip6KOpage[,2] = round(ip6KOpage[,2],3)

ggplot(data=ip6KOpage, aes(x=cell, y=value)) +
  geom_bar(stat="identity",width=.75,color="black",fill="white") +
  theme_pubr() +
  scale_y_continuous(name="ng IP6 / 1E6 Cells",limits=c(0,160),expand=c(0,0)) +
  geom_text(aes(label=round(value),vjust=-1)) +
  scale_x_discrete(name="",limits = c("HEK293FT","IPPK-KO","IPMK-KO"))

#Fig 2C: IP5
#Export .eps at 345 width, 225 height
ip5KOpage = read.csv(file="fig2cData-IP5page.csv",header=T)
ip5KOpage[,2] = round(ip5KOpage[,2],3)

ggplot(data=ip5KOpage, aes(x=cell, y=value)) +
  geom_bar(stat="identity",width=.75,color="black",fill="white") +
  theme_pubr() +
  scale_y_continuous(name="Relative Levels of \n IP5 / 1E6 Cells",
                     limits=c(0,2.4),expand=c(0,0)) +
  geom_text(aes(label=value,vjust=-1)) +
  scale_x_discrete(name="",limits = c("HEK293FT","IPPK-KO","IPMK-KO"))

#Fig 2E: Infectious particle production from HIV from HEK293FT, IPPK-kO, IPMK-KO cells
#Export .eps at 400 width, 350 height
ip6KO = read.csv(file="fig2eData-allKO.csv",header=T)
i.summary = ip6KO %>% group_by(virus,cell) %>% summarise(
  sd = sd(values,na.rm=T),
  mean = mean(values))
limits = aes(ymax=mean+sd,ymin=mean-sd)

ggplot(i.summary,aes(cell,mean)) +
  geom_crossbar(aes(x=cell,y=mean,ymin=0.0002,ymax=mean),width=0.75,size=0.3) +
  geom_errorbar(limits,width=0.25) +
  annotation_logticks(side="l") +
  theme_pubr() +
  scale_y_continuous(trans='log10',labels=percent,expand=c(0,0),limits=c(0.0002,4)) +
  scale_x_discrete(limits=c("HEK293FT","IPPK-KO","IPMK-KO")) +
  labs(x="",y="Infectious Particle Production \n Normalized to HEK293FT") +
  geom_dotplot(aes(cell,values),data=ip6KO,binwidth=0.1,binaxis="y",
               stackdir="center",fill="white",dotsize=0.5)


#Figure 3: HIV IP6 quantification from 33% PAGE
#(HEK293FT & IPPK-KO, +/- Vector, IPPK, or MINPP1 )

#Fig 3D: IP6
#Export .eps at 450 width, 225 height
ip6page = read.csv(file="fig3dData-IP6page.csv",header=T)
ip6page$value = round(ip6page$value,3)

ggplot(ip6page,aes(gene,value,cell)) +
  geom_bar(stat="identity",width=.75,color="black",fill="white") +
  facet_wrap(~cell, strip.position="bottom",scales="free_x") +
  theme_pubr() +
  theme(panel.spacing=unit(0.2,"lines"),strip.placement="outside") +
  geom_text(aes(label=value,vjust=-1)) +
  scale_y_continuous(name="ng IP6 / 1E6 Cells",expand=c(0,0),limits=c(0,800)) +
  scale_x_discrete(name="",limits=c("Vector","IPPK","MINPP1"))

#Fig 3E: IP5
#Export .eps at 470 width, 225 height
ip5page = read.csv(file="fig3eData-IP5page.csv",header=T)
ip5page$value = round(ip5page$value,3)

ggplot(ip5page,aes(gene,value,cell)) +
  geom_bar(stat="identity",width=.75,color="black",fill="white") +
  facet_wrap(~cell, strip.position="bottom",scales="free_x") +
  theme_pubr() +
  theme(panel.spacing=unit(0.2,"lines"),strip.placement="outside") +
  geom_text(aes(label=value,vjust=-1)) +
  scale_y_continuous(name="Relative Levels of \n IP5 / 1E6 Cells",expand=c(0,0),
                     limits=c(0,1.5)) +
  scale_x_discrete(name="",limits=c("Vector","IPPK","MINPP1"))


#Figure 4: MINPP1 Toxicity Analysis

#Fig 4C: MINPP1 Loss of GFP Signal
#Export .eps at 500 width, 400 height
minLoss = read.csv(file="fig4cData-MINPPloss.csv",header=T)

ggplot(minLoss, aes(x=day, y=value, group=cell)) +
  geom_line(aes(linetype=cell)) +
  geom_point(aes(shape=cell),size=3) +
  theme_pubr() +
  theme(legend.position="bottom",legend.title=element_blank()) +
  guides(linetype=guide_legend(nrow=2,byrow=TRUE)) +
  scale_y_continuous(name="% GFP + Cells",labels=percent,limits=c(0,1.4),
                     breaks=seq(0,1.4,by=.2)) +
  xlab("Days Post Transduction")

#Fig 4D: MINPP1 Loss of GFP Signal Last Day Barchart
#Export .eps at 500 width, 400 height
minLossLast = read.csv(file="fig4dData-minppLast.csv",header=T)
m.summary = minLossLast %>% group_by(cell,gene) %>% summarise(
  sd = sd(value,na.rm=T),
  mean = mean(value))
limits = aes(ymax=mean+sd,ymin=mean-sd)

ggplot(m.summary, aes(gene,mean,cell)) +
  geom_bar(stat="identity",width=.75,color="black",fill="white") +
  facet_wrap(~cell, strip.position="bottom",scales="free_x") +
  theme_pubr() +
  theme(panel.spacing=unit(0.2,"lines"),strip.placement="outside") +
  scale_y_continuous(name="% GFP + Cells on Last Day",labels=percent,expand=c(0,0),
                     limits=c(0,1.9)) +
  scale_x_discrete(name="",limits=c("Ctl-GFP","MINPP1-GFP")) +
  geom_errorbar(limits,width=0.05) +
  geom_dotplot(aes(gene,value),data=minLossLast,binwidth=0.1,binaxis="y",
               stackdir="center",fill="white",dotsize=0.25)


#Figure 5: HIV relative infectious particle production

#Fig 5B: HIV
virus = read.csv(file="fig5bData-HIV.csv",header=T)
virus$Gene<-factor(virus$Gene,levels=c("Vector","IPPK","MINPP1"))
v.summary = virus %>% group_by(Cell,Gene) %>% summarise(
  sd = sd(Values,na.rm=T),
  mean = mean(Values))
limits = aes(ymax=mean+sd,ymin=mean-sd)

#Barplot
#Export .eps at 600 width, 350 height
ggplot(v.summary,aes(Gene,mean,Cell)) +
  geom_crossbar(aes(x=Gene,y=mean,ymin=0.0002,ymax=mean),width=0.75,size=0.3) +
  geom_errorbar(limits,width=0.25) +
  annotation_logticks(side="l") +
  facet_wrap(~Cell, strip.position="bottom",scales="free_x") +
  theme_pubr() +
  theme(panel.spacing=unit(0.2,"lines"),strip.placement="outside") +
  scale_y_continuous(trans='log10',labels=percent,expand=c(0,0),limits=c(0.0002,2)) +
  scale_x_discrete(limits=c("Vector","IPPK","MINPP1")) +
  xlab("") + ylab("Infectious Particle Production \n Normalized to HEK293FT Vector") +
  geom_dotplot(aes(Gene,Values),data=virus,binwidth=0.1,binaxis="y",
               stackdir="center",fill="white",dotsize=0.5)

#Fig 5D: HIV Western Data; Lysate Bargraph
ip6Western = read.csv(file="fig5dData-western.csv",header=T)
ip6Western$Gene<-factor(ip6Western$Gene,levels=c("Vector","IPPK","MINPP1"))
w.summary = ip6Western %>% group_by(Cell,Gene) %>% summarise(
  sdLys = sd(normLysate,na.rm=T),
  meanLys = mean(normLysate),
  sdVirus = sd(normVirus,na.rm=T),
  meanVirus = mean(normVirus))
limitsLys = aes(ymax=meanLys+sdLys,ymin=meanLys-sdLys)
limitsVirus = aes(ymax=meanVirus+sdVirus,ymin=meanVirus-sdVirus)

#Export .eps at 400 width, 225 height
ggplot(w.summary,aes(Gene,meanLys,Cell)) +
  geom_crossbar(aes(x=Gene,y=meanLys,ymin=0.0001,ymax=meanLys),width=0.6,size=0.3) +
  #  geom_errorbar(limitsLys,width=0.25) +
  annotation_logticks(side="l") +
  facet_wrap(~Cell, strip.position="bottom",scales="free_x") +
  theme_pubr(x.text.angle=45) +
  theme(panel.spacing=unit(0.2,"lines"),strip.placement="outside") +
  scale_y_continuous(trans='log10',expand=c(0,0),limits=c(0.0001,2)) +
  scale_x_discrete(limits=c("Vector","IPPK","MINPP1")) +
  xlab("") + ylab("Normalized \n Band Density") +
  geom_dotplot(aes(Gene,normLysate),data=ip6Western,binwidth=0.1,binaxis="y",
               stackdir="center",fill="white",dotsize=1.25)

#Fig 5E: HIV Western Data; Virus Bargraph
##Export .eps at 400 width, 225 height
ggplot(w.summary,aes(Gene,meanVirus,Cell)) +
  geom_crossbar(aes(x=Gene,y=meanVirus,ymin=0.0001,ymax=meanVirus),width=0.6,size=0.3) +
  #  geom_errorbar(limitsVirus,width=0.25) +
  annotation_logticks(side="l") +
  facet_wrap(~Cell, strip.position="bottom",scales="free_x") +
  theme_pubr(x.text.angle=45) +
  theme(panel.spacing=unit(0.2,"lines"),strip.placement="outside") +
  scale_y_continuous(trans='log10',expand=c(0,0),limits=c(0.0001,2)) +
  scale_x_discrete(limits=c("Vector","IPPK","MINPP1")) +
  xlab("") + ylab("Normalized \n Band Density") +
  geom_dotplot(aes(Gene,normVirus),data=ip6Western,binwidth=0.1,binaxis="y",
               stackdir="center",fill="white",dotsize=1.25)


#Figure 6: Infection into WT or IPPK-KO target cells

#Fig 6A: HIV Infection of WT or IPPK-KO Target Cells
#Export .eps at 500 width, 375 height
targetVector = read.csv(file="fig6aData-targetCell.csv",header=T)
targetVector$producer_f = factor(targetVector$producer,levels=c("HEK293FT","IPPK-KO"))
tI.summary = targetVector %>% group_by(producer_f,target) %>% summarise(
  sd = sd(normalized,na.rm=T),
  mean = mean(normalized))
limits = aes(ymax=mean+sd,ymin=mean-sd)

ggplot(tI.summary,aes(target,mean,producer_f)) +
  geom_crossbar(aes(x=target,y=mean,ymin=0.0004,ymax=mean),width=0.75,size=0.3) +
  geom_errorbar(limits,width=0.25) +
  annotation_logticks(side="l") +
  facet_wrap(~producer_f, strip.position="bottom",scales="free_x",nrow=1) +
  theme_pubr() +
  theme(panel.spacing=unit(0.2,"lines"),strip.placement="outside") +
  scale_y_continuous(trans='log10',expand=c(0,0),labels=percent,limits=c(0.0004,5)) +
  scale_x_discrete(limits=c("HEK293FT","IPPK-KO")) +
  xlab("") + ylab("Infectious Particle Production \n Normalized to HEK293FT Target") +
  geom_dotplot(aes(target,normalized),data=targetVector,binwidth=0.1,binaxis="y",
               stackdir="center",fill="white",dotsize=0.5)

#Fig 6E: HIV-cd4 into MINPP Target
#Export .eps at 450 width, 375 height
cd4MIN = read.csv(file="fig6eData-cd4MINPP1.csv",header=T)
c.summary = cd4MIN %>% group_by(cell,gene) %>% summarise(
  sd = sd(value,na.rm=T),
  mean = mean(value))
limits = aes(ymax=mean+sd,ymin=mean-sd)

ggplot(c.summary, aes(gene,mean,cell)) +
  geom_bar(stat="identity",width=.75,color="black",fill="white") +
  facet_wrap(~cell, strip.position="bottom",scales="free_x") +
  theme_pubr() +
  theme(panel.spacing=unit(0.2,"lines"),strip.placement="outside") +
  scale_y_continuous(name="Actual : Expected \n Co-Transduction",
                     limits=c(0,1.3),expand=c(0,0)) +
  scale_x_discrete(name="",limits=c("Ctl","MINPP1")) +
  geom_errorbar(limits,width=0.25) +
  geom_dotplot(aes(gene,value),data=cd4MIN,binwidth=0.1,binaxis="y",
               stackdir="center",fill="white",dotsize=0.15)


#Figure 7: Non-lentivirus retroviruses relative infectious particle production
#Export .eps at 600 width, 275 height

#Fig 7A: MLV
virus = read.csv(file="fig7aData-MLV.csv",header=T)
v.summary = virus %>% group_by(Cell,Gene) %>% summarise(
  sd = sd(Values,na.rm=T),
  mean = mean(Values))
limits = aes(ymax=mean+sd,ymin=mean-sd)

ggplot(v.summary,aes(Gene,mean,Cell)) +
  geom_crossbar(aes(x=Gene,y=mean,ymin=0.002,ymax=mean),width=0.75,size=0.3) +
  geom_errorbar(limits,width=0.25) +
  annotation_logticks(side="l") +
  facet_wrap(~Cell, strip.position="bottom",scales="free_x") +
  theme_pubr() +
  theme(panel.spacing=unit(0.2,"lines"),strip.placement="outside") +
  scale_y_continuous(trans='log10',expand=c(0,0),labels=percent,limits=c(0.002,4)) +
  scale_x_discrete(limits=c("Vector","IPPK","MINPP1")) +
  xlab("") + ylab("Infectious Particle Production \n Normalized to \n HEK293FT Vector") +
  geom_dotplot(aes(Gene,Values),data=virus,binwidth=0.1,binaxis="y",
               stackdir="center",fill="white",dotsize=0.75) 

#Fig 7B: MPMV
virus = read.csv(file="fig7bData-MPMV.csv",header=T)
v.summary = virus %>% group_by(Cell,Gene) %>% summarise(
  sd = sd(Values,na.rm=T),
  mean = mean(Values))
limits = aes(ymax=mean+sd,ymin=mean-sd)

ggplot(v.summary,aes(Gene,mean,Cell)) +
  geom_crossbar(aes(x=Gene,y=mean,ymin=0.002,ymax=mean),width=0.75,size=0.3) +
  geom_errorbar(limits,width=0.25) +
  annotation_logticks(side="l") +
  facet_wrap(~Cell, strip.position="bottom",scales="free_x") +
  theme_pubr() +
  theme(panel.spacing=unit(0.2,"lines"),strip.placement="outside") +
  scale_y_continuous(trans='log10',expand=c(0,0),labels=percent,limits=c(0.002,4)) +
  scale_x_discrete(limits=c("Vector","IPPK","MINPP1")) +
  xlab("") + ylab("Infectious Particle Production \n Normalized to \n HEK293FT Vector") +
  geom_dotplot(aes(Gene,Values),data=virus,binwidth=0.1,binaxis="y",
               stackdir="center",fill="white",dotsize=0.75) 


#Figure 8: Lentivirus relative infectious particle production

#Fig 8A: SIV
#Export .eps at 600 width, 300 height
virus = read.csv(file="fig8aData-SIV.csv",header=T)
v.summary = virus %>% group_by(Cell,Gene) %>% summarise(
  sd = sd(Values,na.rm=T),
  mean = mean(Values))
limits = aes(ymax=mean+sd,ymin=mean-sd)

ggplot(v.summary,aes(Gene,mean,Cell)) +
  geom_crossbar(aes(x=Gene,y=mean,ymin=0.00003,ymax=mean),width=0.75,size=0.3) +
  geom_errorbar(limits,width=0.25) +
  annotation_logticks(side="l") +
  facet_wrap(~Cell, strip.position="bottom",scales="free_x") +
  theme_pubr() +
  theme(panel.spacing=unit(0.2,"lines"),strip.placement="outside") +
  scale_y_continuous(trans='log10',expand=c(0,0),labels=percent,limits=c(0.00003,2)) +
  scale_x_discrete(limits=c("Vector","IPPK","MINPP1")) +
  xlab("") + ylab("Infectious Particle Production \n Normalized to \n HEK293FT Vector") +
  geom_dotplot(aes(Gene,Values),data=virus,binwidth=0.1,binaxis="y",
               stackdir="center",fill="white",dotsize=1) 

#Fig 8B: FIV
#Export .eps at 600 width, 275 height
virus = read.csv(file="fig8bData-FIV.csv",header=T)
v.summary = virus %>% group_by(Cell,Gene) %>% summarise(
  sd = sd(Values,na.rm=T),
  mean = mean(Values))
limits = aes(ymax=mean+sd,ymin=mean-sd)

ggplot(v.summary,aes(Gene,mean,Cell)) +
  geom_crossbar(aes(x=Gene,y=mean,ymin=0.002,ymax=mean),width=0.75,size=0.3) +
  geom_errorbar(limits,width=0.25) +
  annotation_logticks(side="l") +
  facet_wrap(~Cell, strip.position="bottom",scales="free_x") +
  theme_pubr() +
  theme(panel.spacing=unit(0.2,"lines"),strip.placement="outside") +
  scale_y_continuous(trans='log10',expand=c(0,0),labels=percent,limits=c(0.002,2)) +
  scale_x_discrete(limits=c("Vector","IPPK","MINPP1")) +
  xlab("") + ylab("Infectious Particle Production \n Normalized to \n HEK293FT Vector") +
  geom_dotplot(aes(Gene,Values),data=virus,binwidth=0.1,binaxis="y",
               stackdir="center",fill="white",dotsize=0.75) 

#Fig 8C: EIAV
#Export .eps at 600 width, 275 height
virus = read.csv(file="fig8cData-EIAV.csv",header=T)
v.summary = virus %>% group_by(Cell,Gene) %>% summarise(
  sd = sd(Values,na.rm=T),
  mean = mean(Values))
limits = aes(ymax=mean+sd,ymin=mean-sd)

ggplot(v.summary,aes(Gene,mean,Cell)) +
  geom_crossbar(aes(x=Gene,y=mean,ymin=0.002,ymax=mean),width=0.75,size=0.3) +
  geom_errorbar(limits,width=0.25) +
  annotation_logticks(side="l") +
  facet_wrap(~Cell, strip.position="bottom",scales="free_x") +
  theme_pubr() +
  theme(panel.spacing=unit(0.2,"lines"),strip.placement="outside") +
  scale_y_continuous(trans='log10',expand=c(0,0),labels=percent,limits=c(0.002,2)) +
  scale_x_discrete(limits=c("Vector","IPPK","MINPP1")) +
  xlab("") + ylab("Infectious Particle Production \n Normalized to \n HEK293FT Vector") +
  geom_dotplot(aes(Gene,Values),data=virus,binwidth=0.1,binaxis="y",
               stackdir="center",fill="white",dotsize=0.75) 


#Figure 9: EM data analysis

#Fig 9E: Spheres
#(Export EPS 700x550)
emData=read.csv(file="fig9eData-EMspheres.csv",header=T)
emData$virus = factor(emData$virus,levels=c("HIV","SIV","FIV","EIAV"))

ggplot(emData,aes(ip6,value,virus)) +
  geom_boxplot(aes(fill=ip6)) +
  facet_wrap(~virus, strip.position="bottom",scales="free_x",nrow=1) +
  theme_pubr(legend="none") +
  theme(panel.spacing=unit(0.2,"lines"),strip.placement="outside") +
  scale_y_continuous(name=expression("# of Spherical VLPs / 8 μm"^2),
                     limits=c(0,475),expand=c(0,0)) +
  xlab("") +
  geom_dotplot(aes(ip6,value,fill=ip6),data=emData,binwidth=5,binaxis="y",
               stackdir="center",dotsize=1)

#Fig 9F: Tubular VLPs
#(Export EPS 700x550)
emDataTube=read.csv(file="fig9fData-EMtubes.csv",header=T)
emDataTube$virus = factor(emDataTube$virus,levels=c("HIV","SIV","FIV","EIAV"))

ggplot(emDataTube,aes(ip6,value,virus)) +
  geom_boxplot(aes(fill=ip6)) +
  facet_wrap(~virus, strip.position="bottom",scales="free_x",nrow=1) +
  theme_pubr(legend="none") +
  theme(panel.spacing=unit(0.2,"lines"),strip.placement="outside") +
  scale_y_continuous(name=expression("# of Tubular VLPs / 8 μm"^2),
                     limits=c(0,25),expand=c(0,0)) +
  xlab("") +
  geom_dotplot(aes(ip6,value,fill=ip6),data=emDataTube,
               binwidth=0.25,binaxis="y",stackdir="center",dotsize=1)


